<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>page</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="layui/css/layui.css" media="all">
  <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form" name="body" action="Hello">
  <div class="layui-form-item">
    <label class="layui-form-label">角色名</label>
    <div class="layui-input-inline">
      <input type="text" name="roleName" id="roleName" required lay-verify="required" placeholder="请输入角色名"
             autocomplete="off" class="layui-input"/>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">激活</label>
    <div class="layui-input-inline">
      <input type="checkbox" name="activate" id="ativate" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF"/>
    </div>
  </div>

  <div class="layui-form-item">
    <label class="layui-form-label">备注</label>
    <div class="layui-input-inline">
      <input type="text" name="remake" id="remake" required lay-verify="required" placeholder="请输入角色名"
             autocomplete="off" class="layui-input"/>
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

<script src="layui/layui.js" charset="utf-8"></script>

<script>
  //Demo
  layui.use(['form', 'jquery'], function () {
    var form = layui.form;
    var $ = layui.$;
    form.on('submit()', function (data) {
      var paramenter = $("form").serialize();
      $.ajax({
        type: 'post'
        , data: paramenter
        , url: 'roleInsert'
        , success: function (data) {
          if (data) {
            layer.alert("提交成功");
            layer.close(layer.index);
            window.parent.location.reload();
          } else {
            layer.alert("提交失败")
          }
        }
      });
      return false;
    });
  });
</script>
</body>
</html>